package com.num2.service.lkw;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;

import com.num2.dao.lkw.IInformationDao;
import com.num2.form.xjg.LoginForm;
import com.num2.model.lkw.InformationModel;


@Service
public class InformationService {
	@Resource
	private SqlSessionFactory sqlSessionFactory;
	 public InformationModel select(LoginForm loginform,HttpSession session){
	        //打开session
	        SqlSession sqlSession = sqlSessionFactory.openSession();
	        //通过 注解 获取 接口实现类的对象
	        IInformationDao informationDao = sqlSession.getMapper(IInformationDao.class);
	        int user_id = informationDao.selectName((String) session.getAttribute("user_name"));
	        //获取结果
	        List<InformationModel> informationModel = informationDao.select(user_id);
	        //关闭会话
	        sqlSession.close();
	        if (informationModel.size() > 0)
	            return informationModel.get(0);
	        else
	            return null;
	    }

	    public SqlSessionFactory getSqlSessionFactory() {
	        return sqlSessionFactory;
	    }

	    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
	        this.sqlSessionFactory = sqlSessionFactory;
	    }
	}


